<?php


namespace Swb\Shop\Service;




use Hyperf\DbConnection\Db;
use Swb\Shop\Helper\BrandTrait;
use Swb\Shop\Helper\ShopTrait;
use Swb\Shop\Model\CConfigTemplate;
use Swb\Shop\Model\File;

/**
 * Class ActivityServiceImpl
 * @package App\Service\Impl
 * User:zhangboss
 * 模板服务
 */
class ConfigTemplateService
{
	use ShopTrait,BrandTrait;

	protected $brandAllianceServiceImpl;

	public function getConfig($template_id)
	{
		$data = CConfigTemplate::query()->where('id',$template_id)->first();
		$data['background_image'] = File::query()->where('id',$data['file_id'])->value('access_path');
		$config= $data['configs']?json_decode($data['configs'],true):[];
		if($config)
		{
			foreach ($config as &$item)
			{
				switch ($item['type'])
				{
					case 1:
						$item['info'] = $this->get_active_shop($item['relation_id'],1);
						break;
					case 2:
					case 3:
						$item['info'] =  $this->get_active_shop($item['relation_id'],$item['type']);
						break;
					case 4:
						$item['info'] = $this->get_active_brand($item['relation_id']);

				}
			}

		}
		$data['configs'] = $config;
		return $data;
	}
}